class Member:
    def __init__(self, level):
        self.level = level

    @property
    def discount_rate(self):
        if self.level == "普通会员":
            return 0.95
        elif self.level == "高级会员":
            return 0.9
        elif self.level == "至尊会员":
            return 0.8
        return 1


class CartItem:
    def __init__(self, name, price, quantity, member=None):
        self.name = name
        self.price = price
        self.quantity = quantity
        self.member = member

    @property
    def total_price(self):
        if self.member:
            return self.price * self.quantity * self.member.discount_rate
        return self.price * self.quantity


class ShoppingCart:
    def __init__(self):
        self.items = []

    def add_item(self, item):
        self.items.append(item)

    def apply_discount(self):
        total = 0
        for item in self.items:
            total += item.total_price
        return total

    def show(self):
        print("购物车内容：")
        for item in self.items:
            if item.member:
                print(
                    f"{item.name} x {item.quantity}，原价：{item.price * item.quantity:.2f} 元，折扣后：{item.total_price:.2f} 元，会员等级：{item.member.level}")
            else:
                print(f"{item.name} x {item.quantity}，总价：{item.total_price:.2f} 元")
        total = self.apply_discount()
        print(f"折扣后总价：{total:.2f} 元")


if __name__ == "__main__":
    cart = ShoppingCart()
    member1 = Member("高级会员")
    member2 = Member("普通会员")

    try:
        apple_quantity = int(input("请输入苹果的数量："))
        banana_quantity = int(input("请输入香蕉的数量："))
        milk_quantity = int(input("请输入牛奶的数量："))

        item1 = CartItem("苹果", 5, apple_quantity, member1)
        item2 = CartItem("香蕉", 3, banana_quantity, member2)
        item3 = CartItem("牛奶", 8, milk_quantity)

        cart.add_item(item1)
        cart.add_item(item2)
        cart.add_item(item3)

        cart.show()
    except ValueError:
        print("输入无效，请输入有效的整数。")

